//
//  StatisticsServer.hpp
//  Simulation
//
//  Created by Christopher Kemsley on 3/7/12.
//  Copyright (c) 2012 iAppolopolis. All rights reserved.
//

#ifndef Simulation_StatisticsServer_hpp
#define Simulation_StatisticsServer_hpp

#define	StatsNamespaceBegin	namespace Statistics {
#define	StatsNamespaceEnd	}

#include <string>
#include <map>
#include <ostream>
#include <fstream>
#include "Types.hpp"

SimNamespaceBegin





class	Server ;
struct	StateStat ;





extern char const*	const sIdle			;
extern char const*	const sTXControl		;
extern char const*	const sTXControlFail	;
extern char const*	const sTXReturn		;
extern char const*	const sTXReturnFail	;
extern char const*	const sTXData			;
extern char const*	const sTXDataFail		;





struct	StateStatServer
{
	static std::string	rowPrefix ; // for all rows
} ;






// Note: C-Strings should be static string literals

struct	StateStat
{
	StateStat	( std::string const & name , char const * defaultState ) ;
	~StateStat	() ;
	
	
	void	operator<<	( char const * state ) ; // non-retroactive
	void	operator<=	( char const * state ) ; // retroactive
	
	
private:
	typedef std::map<std::string,UInteger>	Map ;
	std::string const	mName ;
	
	// Updates
	char const *	mState ;
	UInteger		mSlot ;
	
	// Record
	Map				mPeriods ;
	
	void	_add ( char const * state , UInteger value ) ;
	
	friend std::ostream&	operator<<	( std::ostream & stream , StateStat const & node ) ;
} ;





SimNamespaceEnd

#endif
